package cn.tedu.ivos.application.controller;

import cn.tedu.ivos.application.pojo.dto.ApplicationQuery;
import cn.tedu.ivos.application.pojo.dto.ApplicationSaveParam;
import cn.tedu.ivos.application.pojo.vo.ApplicationVO;
import cn.tedu.ivos.application.service.ApplicationService;
import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.vehicle.service.VehicleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/application")
public class ApplicationController {
    @Autowired
    ApplicationService applicationService;
    @Autowired
    VehicleService vehicleService;
    @PostMapping("save")
    public JsonResult saveApplication(ApplicationSaveParam applicationSaveParam){
        log.debug("保存申请表参数：{}",applicationSaveParam);
        applicationService.saveApplication(applicationSaveParam);
        return JsonResult.ok();
    }
    @GetMapping("select")
    public JsonResult selectApplication(ApplicationQuery applicationQuery){
        log.debug("查询申请单列表参数：{}",applicationQuery);
        List<ApplicationVO> list=applicationService.selectApplication(applicationQuery);
        return JsonResult.ok(list);
    }
    @PostMapping("cancel/{id}")
    public JsonResult cancel(@PathVariable Long id){
        log.debug("撤销申请单参数：{}",id);
        applicationService.updateStatus(id);
        return JsonResult.ok();
    }
    @PostMapping("distribute/{applicationId}/{vehicleId}")
    public JsonResult distributeVehicle(
            @PathVariable Long applicationId,@PathVariable Long vehicleId){
        log.debug("车辆分配，applicationId={},vehicleId={}",applicationId,vehicleId);
        applicationService.distributeVehicle(applicationId,vehicleId);
        return JsonResult.ok();
    }
    @PostMapping("back/{applicationId}/{vehicleId}")
    public JsonResult back(@PathVariable Long applicationId,@PathVariable Long vehicleId){
        log.debug("还车方法,applicationId{},vehicle{}",applicationId,vehicleId);
        applicationService.back(applicationId,vehicleId);
        return JsonResult.ok();
    }
}
